package test;

import java.util.Arrays;

public class MyCircularQueue {
    private int[] elem;
    private int usedSize;
    private int front;
    private int rear;
    public MyCircularQueue(int k){
        this.elem=new int[k];
    }
    public boolean isEmpty() {
        if(this.front==this.rear){
            return true;
        }
        return false;
    }
    public boolean isFull(){
        if((this.rear+1)%this.elem.length==this.front){
            return true;
        }
        return false;
    }
    public boolean enQueue(int value){
        if(isFull()){
            return false;
//            this.elem= Arrays.copyOf(this.elem,this.elem.length*2);
        }
        this.elem[this.rear]=value;
        this.rear=(this.rear+1)%this.elem.length;
        return true;
    }
    public boolean deQueue(){
        if(isEmpty()){
            return false;
        }
        this.front=(this.front+1)%this.elem.length;
        return true;
    }
    public int Front(){
        if (isEmpty()){
            return -1;
        }
        return this.elem[this.front];
    }
    public int Rear(){
        if (isEmpty()){
            return -1;
        }
        if(this.rear == 0) {
            return this.elem[this.elem.length-1];
        }
        return this.elem[this.rear-1];
    }
}
